package bid.yanhj.onclicklistenter.onclicklistenter;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button btn1, btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn1 = findViewById(R.id.on_btn_1);
        btn2 = findViewById(R.id.on_btn_2);


        btn1.setOnClickListener(new MyOnClickListener() {
            @Override
            public void onClick(View v) {
                super.onClick(v);
                Toast.makeText(MainActivity.this, "btn执行逻辑", Toast.LENGTH_SHORT).show();
            }
        });

        btn2.setOnClickListener(new MyOnClickListener() {
            @Override
            public void onClick(View v) {
                super.onClick(v);
                Toast.makeText(MainActivity.this, "btn2执行逻辑", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

class MyOnClickListener implements View.OnClickListener {

    @Override
    public void onClick(View v) {
        // 所有按钮都会执行
        v.setAlpha(0.6F);
    }
}